
export const toastRef = { value: null }
export const choiceRef = { value: null }
export const choiceTasks = []

/**
 * 
 * @param {string} title 
 * @param {string} content 
 * @param {()=>void} then 回调函数
 * @returns Toast组件
 */
export function showToast (title, content, then, showTime = 2000) {
	toastRef.value.title = title
	toastRef.value.showTime = showTime
	toastRef.value.content = content || ""
	toastRef.value.then = then
	toastRef.value.show = true
	return toastRef.value
}
/**
 * 
 * @param {string} title 标题
 * @param {Array<string>} list 内容
 * @param {boolean} choice 是否显示取消
 * @param {Function} then 确定后回调函数
 * @param {Funciton} _catch 取消后回调函数
 * @param {string} enterContent 确定按钮内容
 * @returns 
 */
export function choice (title, list, choice, then, _catch, enterContent) {
	if (typeof list == "string") {
		list = [list]
	}
	if (choiceTasks.length == 0 && choiceRef.value.hide) {
		choiceRef.value.title = title
		choiceRef.value.list = list
		choiceRef.value.then = then
		choiceRef.value._catch = _catch
		choiceRef.value.show = true
		choiceRef.value.choice = choice || false
		choiceRef.value.enterContent = enterContent || "确定"
	} else {
		choiceTasks.push(() => {
			choiceRef.value.title = title
			choiceRef.value.list = list
			choiceRef.value.then = then
			choiceRef.value._catch = _catch
			choiceRef.value.show = true
			choiceRef.value.choice = choice || false
			choiceRef.value.enterContent = enterContent || "确定"
		})
	}
	return choiceRef.value
}

export const isShow = () => {
	return choiceRef.value.show || toastRef.value.show
}